package com.szw.dlyk.web;
import com.szw.dlyk.result.NameValue;
import com.szw.dlyk.result.Result;
import com.szw.dlyk.result.SummaryData;
import com.szw.dlyk.service.StatisticService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据统计Controller
 */
@RestController
public class StatisticController {

    @Resource
    private StatisticService statisticService;

    @GetMapping(value = "/api/summary/data")
    public Result summaryData() {
        SummaryData summaryData = statisticService.loadSummaryData();
        return Result.ok(summaryData);
    }

    /**
     *     { value: 20, name: '成交' },
     *     { value: 60, name: '交易' },
     *      { value: 80, name: '客户' },
     *       { value: 100, name: '线索' }
     * @return
     */
    @GetMapping(value = "/api/saleFunnel/data")
    public Result saleFunnelData() {
        List<NameValue> nameValueList = statisticService.loadSaleFunnelData();
        return Result.ok(nameValueList);
    }

    @GetMapping(value = "/api/sourcePie/data")
    public Result sourcePieData() {
        /**
         *   [
         *       { value: 1048, name: 'Search Engine' },
         *       { value: 735, name: 'Direct' },
         *       { value: 580, name: 'Email' },
         *       { value: 484, name: 'Union Ads' },
         *       { value: 300, name: 'Video Ads' }
         *   ]
         *
         */
        List<NameValue> nameValueList = statisticService.loadSourcePieData();
        return Result.ok(nameValueList);
    }
}
